<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>vue中非父子组件传值(bus/总线/发布订阅模式/观察者模式)</title>
    <script src="../vue.js"></script>
   
</head>
<body>
    <div id="app">  
           <child content="Dell"></child>
           <child content="Lee"></child> 
    </div>   
    
    <script>

        //  1.vuex
        //  2.bus/总线/发布订阅模式/观察者模式

        Vue.prototype.bus = new Vue();
      
        Vue.component('child',{
            data: function(){
                return {
                    //  conmtent  拷贝
                    selfContent = this.content
                }
            },
            props: {
                content: String
            },
            template: '<div @click="handleClick">Child</div>',
            methods: {
                handleClick: function() {
                    this.bus.$emit('change'.this.selfContent)
                }
            },
            mounted: function() {
                // this 作用域被改变
                var this_ = this
                this.bus.$on('change',function( msg ){                   
                    this.selfContent = mag
                })
            }
        })
    
        var root = new Vue({
            el: '#app',            
           
        });
    </script>
</body>
</html>